﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CPPEI.Coolzon.Service.Contract;
using CPPEI.Coolzon.Event.NCL;
using Sunboxsoft.ChanceData.ServiceProxy.MainServiceRef;

namespace CPPEI.Coolzon.UI.Views.EventProxies
{
    public class RespGetViewStateHandler : BaseResponseHandler<Service.Contract.RespGetViewStateData>
    {
        protected override void OnHandle(RemoteEventProxy remoteEventProxy, Response response, RespGetViewStateData responseData)
        {
            if(string.Equals(responseData.ServerIp, UIContext.Current.MainServerIP) && responseData.ServerPort == UIContext.Current.MainServerPort)
            {
                NCLEndGetViewState @event = new NCLEndGetViewState();
                @event.State = NCLEventState.Finished;
                if (responseData.HasViewState)
                {
                    @event.HasViewStateToken = true;
                    @event.ViewStateToken = responseData.ViewStateToken;
                }
                else
                {
                    @event.HasViewStateToken = false;
                }

                NCLEventBus.PublishAsync(@event);

                Common.Logger.InfoToTag(Library.LogTag, "获取到主服务 {0}:{1} 的视图状态:是否有:{2},Token:{3}", responseData.ServerIp, responseData.ServerPort, responseData.HasViewState, responseData.ViewStateToken);
            }
            else
            {
                Common.Logger.InfoToTag(Library.LogTag, "获取到其他服务 {0}:{1} 的视图状态:是否有:{2},Token:{3}", responseData.ServerIp, responseData.ServerPort, responseData.HasViewState, responseData.ViewStateToken);
            }
        }
    }
}
